package com.mayo.feaf;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.mayo.feaf.comun.ComunMapasActivity;
import com.mayo.feaf.object.MarcadorObject;

public class MapaActivity extends Activity {

	private MarcadorObject marcador;
	
	@Override
	protected  void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mapa);
		
		getActionBar().setTitle(R.string.tit_mapa);
		getActionBar().setSubtitle(R.string.tit_localizacion);
		getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
				| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP
				| ActionBar.DISPLAY_SHOW_CUSTOM);
		
		GoogleMap mapa = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
		        .getMap();
		
		if (getIntent().getExtras() != null) {
			Bundle todosParametros = getIntent().getExtras();
			marcador = todosParametros.getParcelable("marcador");
			
			Double latDouble = Double.parseDouble(marcador.getLatitud());
			Double lonDouble = Double.parseDouble(marcador.getLongitud());
			LatLng location = new LatLng(latDouble, lonDouble);
			ComunMapasActivity.animateCamara(mapa, location);
			
			ComunMapasActivity.mostrarMarcador(mapa, location, R.drawable.ic_action_place, 
					marcador.getTitulo(), marcador.getSnippet());
		}
	}
	
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            this.finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

}
